import { createRouter, createWebHistory } from 'vue-router'
const routes = [
  {
    path: '/main',
    name: '首页',
    component: () => import('../view/component/MainView.vue'),
    // 需要认证
    meta: {
      requiresAuth: true
    }
  },{
    path: '/',
    name: '欢迎',
    component: () => import('../view/WelcomeView.vue'),
    // 隐藏导航
    meta:{
      hideNavigation: true
    }
  },{
    path: '/login',
    name: '登录',
    component: () => import('../view/LoginView.vue'),
    meta:{
      hideNavigation: true,
      // 仅限游客访问
      guestOnly: true
    }
  },{
    path: '/register',
    name: '注册',
    component: () => import('../view/RegisterView.vue'),
    meta:{
      hideNavigation: true
    }
  },{
    path: '/404',
    name: '404',
    component: () => import('../view/NotFound.vue'),
    meta:{
      hideNavigation: true}
    },{
    path: '/owner',
    name: '个人中心',
    component: () => import('../view/component/OwnerView.vue'),
  },{
    path: '/recommend',
    name: '推荐',
    component: () => import('../view/component/RecommendView.vue'),
    children:[
      {
        path: 'recommendList',
        name: '推荐列表',
        component: () => import('../components/RecommendList.vue'),
      }
    ]
  },{
    path: '/order',
    name: '订单',
    component: () => import('../view/component/OrderView.vue'),
  },{
      path: '/recommendDetail/:id',  
      name: '推荐详情',
      component: () => import('../components/RecommendDetail.vue'),
    },{
      path: '/profileLink',
      name: '个人资料',
      component: () => import('../components/ProfileLink.vue'),
    },{
      path: '/updateProfile',
      name: '更新个人资料',
      component: () => import('../components/UpdatedProfile.vue'),
    },{
    path: '/find',
    name: '发现',
    component: () => import('../view/component/FindView.vue'),
    // 隐藏导航
    meta:{
      hideNavigation: true
    }
  }
]
// 创建路由实例并传递 `routes` 配置
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
  // 滚动行为，如果有保存的滚动位置，则恢复到该位置
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  }
})

export default router